<template>
  <div class="back">
    <img src="../assets/logo.png"
         style="margin-top:20vh;"><br>
    <div class="back2"><br><br><br><br>
      <div style="text-align: left;
      margin-left: 20px;
      margin-top: -65px;">
        <i class="el-icon-back"
           size="medium"
           style="font-size: 25px;;"
           @click="back()"></i>
      </div>
      <div style="width:300px;margin:auto;margin-top: 50px;">
        <el-input v-model="in_account"
                  class="input3"
                  prefix
                  prefix-icon="el-icon-bank-card"
                  size="medium"></el-input>
        <br><br>
        <el-input v-model="in_password"
                  class="input3"
                  placeholder=""
                  prefix-icon="el-icon-lock"
                  show-password
                  size="medium"></el-input>
        <br><br><br>
        <div style="margin:10px;text-align:center">
          <el-button autocomplete="off"
                     class="botton"
                     size="medium"
                     @click="loginCheck()">登录
          </el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>

export default {
  data () {
    return {
      userDTO: '',
      in_account: '',
      in_password: '',
    }
  },
  methods: {
    back () {
      this.$router.push({
        path: '/public',
      })
    },
    termCheck () {
      this.$http.post("/semester/1", {
        state: 1, page: 1
      }).then((res) => {
        this.$store.commit("setTerm", res.data.data[0].term)
      })
    },
    loginCheck () {
      this.termCheck()
      this.$http.post("/user/login", {
        account: this.in_account,
        password: this.in_password
      }).then((res) => {
        if (!res.data.data) {
          this.$message(res.data.errorMsg)
          return false
        }
        this.userDTO = res.data.data[0]
        this.$store.commit("setUser", this.userDTO)
        this.$store.commit("setToken", res.data.data[1])
        if (this.userDTO.job === 0) {
          this.$router.push({
            path: '/manager',
          })
        } else if (this.userDTO.job === 1) {
          this.$router.push({
            path: '/teacher',
          })
        } else if (this.userDTO.job === 2) {
          this.$router.push({
            path: '/tester',
          })
        } else if (this.userDTO.job === 3) {
          this.$router.push({
            path: '/student',
          })
        }
        else (this.$message("用户无权限！"))
      })
    },
  }

}
</script>

<style scoped>
.botton {
  border-radius: 10px;
  color: darkorange;
  background-color: #525151;
  border-color: rgb(255, 143, 7);
}

.botton:hover,
.botton:focus {
  border-radius: 10px;
  background: rgb(255, 200, 133);
  border-color: darkorange;
  color: black;
}

.back {
  margin: auto;

  text-align: center;
  height: 100vh;
  background-color: #525151;
  color: darkorange;
}

.back2 {
  border-radius: 30px;
  border: 1px solid darkorange;
  margin: auto;
  height: 300px;
  background-color: #525151;
  color: darkorange;
  width: 500px;
  box-shadow: 10px 10px rgba(0, 0, 0, 0.219), 0 0 6px rgba(0, 0, 0, 0.04);
}

.input3 /deep/ .el-input__inner {
  border-radius: 10px;
  color: darkorange;
  border: 2px solid darkorange;
  background-color: transparent !important;
}
</style>
